<?php
class ReviewsController extends AppController {
    public $helpers = array('Html', 'Form','Session');
    public $components = array('Session','Auth');
    public $uses=array('User','Order','Publicpage','Review');
    public function index(){
      $userid= $this->Auth->User('id');
      $this->set('title_for_layout', 'Отправить отзыв');
      $this->set('user_name_sidebar', AppController::getUserName($userid));
    }
    public function send(){
      if ($this->request->is('post')) {
        $userid= $this->Auth->User('id');
        $user_data=$this->User->findById($userid);
        $user_login=$user_data['User']['login'];
        $this->request->data['Review']['from']= $user_login;
        $this->request->data['Review']['timestamp'] = DboSource::expression('NOW()');
        $this->Review->create();
        $message=$this->request->data['Review']['message'];
        if ($this->Review->save($this->request->data)) {
          $this->Session->setFlash(__('Ваш отзыв успешно отправлен!'));
          $headers= "MIME-Version: 1.0\r\n";
          $headers .= "Content-type: text/html; charset=utf-8\r\n";
          $headers.="From: support@radioheart.ru\r\n";
          $message="Новый отзыв от ".$user_login."<br />Текст сообщения: ".$message;
          mail("rh@radioheart.ru", "RadioHeart - качественный радио хостинг",$message,$headers);
          $this->redirect(array('action' => 'index'));
        }
      }
    }
}


?>